import { defineAsyncComponent } from 'vue'
const components = import.meta.glob('./**/*.vue')

export default function install(app) {
  for (const [key, value] of Object.entries(components)) {
    const reg = /\//g
    // 过滤非当前路径一级目录下以外的vue文件
    const isParent = key.match(reg).length == 2 ? true : false
    if (!isParent) continue
    // 拆分路径 取最后子级的上一级
    const arr = key.split('/')
    const name = arr[arr.length - 2]
    app.component(name, defineAsyncComponent(value))
  }
}